<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 遍历器可以遍历数组，伪数组，set()和map();
    // keys():键(下标)   values():值(元素)   entries():键和值
    var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
    // var obj = arr.keys();
    // var obj = arr.values();
    // var obj = arr.entries();
    // console.log(obj);
    // console.log(obj.next());
    // console.log(obj.next());

    // for (var k of obj) {
    //     console.log(k);
    // }

    // 模拟封装 下标
    function* keysIn(list) {
        for (var i = 0; i < list.length; i++) {
            yield i;
        }
    }

    // 模拟封装 元素
    function* valuesIn(list) {
        for (var i = 0; i < list.length; i++) {
            yield list[i];
        }
    }

    // 模拟封装 下标和元素
    function* entriesIn(list) {
        for (var i = 0; i < list.length; i++) {
            var item = list[i];
            yield [i,item];
        }
    }
    // var obj = keysIn(arr);
    // console.log(obj.next());
    // console.log(obj.next());
    // console.log(obj.next());

    // var obj = valuesIn(arr);
    // console.log(obj.next());
    // console.log(obj.next());
    // console.log(obj.next());

    var obj = entriesIn(arr);
    console.log(obj.next());
    console.log(obj.next());
    console.log(obj.next());



</script>

</html>